package com.salton123.groupbargain.ui

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.salton123.dytt.RequestHelper
import com.salton123.feature.PermissionFeature
import com.salton123.groupbargain.R
import com.salton123.groupbargain.ui.fm.HelloFragment
import com.salton123.groupbargain.ui.fm.HomeComp
import com.salton123.soulove.sdk.BuildConfig
import com.salton123.ui.base.BaseActivity
import com.salton123.util.FragmentUtils
import kotlinx.android.synthetic.main.aty_main.*


/**
 * User: newSalton@outlook.com
 * Date: 2019-08-03 23:05
 * ModifyTime: 23:05
 * Description:
 */
class MainActivity : BaseActivity() {
    override fun getLayout(): Int = R.layout.aty_main
    private val mHomeComp by lazy { HomeComp() }
    private val mGalleryComp by lazy { HelloFragment() }
    private val mData = arrayOf<Fragment>(mHomeComp, mGalleryComp)

    override fun initVariable(savedInstanceState: Bundle?) {
//        addFeature(EventBusFeature(this))
    }

    @SuppressLint("CheckResult", "MissingPermission")
    override fun initViewAndData() {
        mData.forEach {
            FragmentUtils.add(supportFragmentManager, it, R.id.mainContent)
            FragmentUtils.hide(supportFragmentManager, it)
        }
        FragmentUtils.show(supportFragmentManager, mData[0])
        bottomBarLayout.setOnItemSelectedListener { _, _, currentPosition ->
            mData.forEach {
                FragmentUtils.hide(supportFragmentManager, it)
            }
            FragmentUtils.show(supportFragmentManager, mData[currentPosition])
//            NewMoviePresenter.getNewMovie("https://www.dytt8.net/html/gndy/dyzz/list_23_2.html"
//                , object : NewMovieInfoCallback {
//                    override fun onSuccess(
//                        info: MutableList<MovieInfo>?,
//                        pageList: MutableList<String>?
//                    ) {
//                        println("hello")
//                    }
//
//                    override fun onFailed() {
//                        println("world")
//                    }
//                })
            RequestHelper.movieList(23,1)
        }

        if (BuildConfig.APP_DEVELOP) {
            longToast("开发模式")
        }
        PermissionFeature().onBind()
//        Looper.myQueue().addIdleHandler {
//            PermissionFeature().onBind()
//            true
//        }
    }

    override fun isOpenTitleBar(): Boolean {
        return false
    }

    override fun onBackPressed() {
        super.onBackPressed()
        moveTaskToBack(true)
    }
}